package svgedit.TestSVG;

import static org.junit.Assert.assertTrue;
import org.junit.Test;
import svgedit.gui.Frame;
import svgedit.svg.SVGDocument;
import svgedit.svg.SVGElement;
import svgedit.svg.SVGGroup;
import svgedit.svg.SVGLineElement;
import svgundoredo.GroupElementCommand;

/**
 * test GroupElementCommand class
 */

public class GroupElementCommandTest
{
    
    /**
     * test execute() method
     */
    @Test
    public void testexecute()
    {
        // create new frame
        Frame frame = new Frame();
        Frame f = new Frame();
        SVGDocument d = f.getDocument();
        SVGDocument document;
        document = frame.getDocument();
        SVGGroup group = new SVGGroup(document);
        SVGLineElement element = new SVGLineElement(d);
        SVGGroup gr = new SVGGroup(d);
        group.appendChild(element);
        group.appendChild(element);
        group.appendChild(element);
        gr.appendChild(element);
        SVGElement elements[] = gr.getChildren();
        // check the group before excute
        assertTrue(elements.length == 1);
        assertTrue(group.getChildren().length == 3);
        GroupElementCommand g = new GroupElementCommand(elements, group);
        g.execute();
        // the group add a new element
        assertTrue(group.getChildren().length == 4);
        
    }
    
    /**
     * test undo() method
     */
    @Test
    public void testundo()
    {
        // create new frame
        Frame frame = new Frame();
        Frame f = new Frame();
        SVGDocument d = f.getDocument();
        SVGDocument document;
        document = frame.getDocument();
        SVGGroup group = new SVGGroup(document);
        SVGLineElement element = new SVGLineElement(d);
        SVGGroup gr = new SVGGroup(d);
        group.appendChild(element);
        group.appendChild(element);
        group.appendChild(element);
        gr.appendChild(element);
        SVGElement elements[] = gr.getChildren();
        assertTrue(elements.length == 1);
        assertTrue(group.getChildren().length == 3);
        GroupElementCommand g = new GroupElementCommand(elements, group);
        g.execute();
        // the group add a new element
        assertTrue(group.getChildren().length == 4);
        g.undo();
        // undo ,become to the original group
        assertTrue(group.getChildren().length == 3);
        
    }
    
}
